import java.util.ArrayList;
import java.util.LinkedList;
import com.google.java.contract.*;

@Invariant("getTotalLength() >= 0")
public class Rollercoaster {

	//private LinkedList<Part> theCoaster;
	
	private ArrayList<Part> theCoaster;
	
	private float totalLength;
	
	public String name;
	
	public Rollercoaster() {
		theCoaster = new ArrayList();
		
		name = "";
	}
	
	@Requires("theCoaster != null")
	@Ensures({"old(theCoaster.size()) == theCoaster.size() - 1", "totalLength > old(totalLength)"})
	public void addPart(Part addThis) {
		//theCoaster.addLast(addThis);
		theCoaster.add(addThis);
		totalLength += addThis.getLength();
	}
	
	public float getTotalLength() {
		return totalLength;
	}
	
	//50 is a magic number
	//need to generalize this to allow for different sized parts
	public Part currentPart(Cart activeCart) {
		int arrayIndex = 0;
		return theCoaster.get(arrayIndex);
	}
	
	public float getStartX() {
		if (theCoaster.isEmpty()) {
			return 0;
		} else {
			return theCoaster.get(0).x;
		}
	}
	
	public float getStartY() {
		if (theCoaster.isEmpty()) {
			return 0;
		} else {
			return theCoaster.get(0).y;
		}
	}
	
	public float getStartZ() {
		if (theCoaster.isEmpty()) {
			return 0;
		} else {
			return theCoaster.get(0).z;
		}
	}
	
	public ArrayList<Part> getCoasterParts() {
		return theCoaster;
	}
}

//Random notes:
	//Editing within a rollercoaster can get tricky, should be doable though
